package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    //按照时间和类型统计
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{time} AND TYPE=#{type}")
    Long countByTimeAndType(@Param("time") String time, @Param("type") String type);

    //按照时间统计
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{time}")
    Long countByTime(@Param("time") String time);

    //次日留存
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{yesterday} AND TYPE='0102' \n" +
            "\tAND user_id IN(SELECT user_id FROM tb_log WHERE log_time=#{today})")
    Long keep(@Param("yesterday") String yesterday, @Param("today") String today);
}